package android.fwirk.plurk;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.jplurk.DateTime;


public class Plurk {
	public final static int PLURK_IS_READ=0;
	public final static int PLURK_IS_UNREAD=1;
	public final static int PLURK_IS_MUTED=2;
	public final static int PLURK_TYPE_PUBLIC=0;
	public final static int PLURK_TYPE_PRIVATE=1;
	public final static int PLURK_TYPE_PUBLIC_RESPONDED=2;
	public final static int PLURK_TYPE_PRIVATE_RESPONDED=3;
	public final static int PLURK_NO_COMMENTS=1;
	public final static int PLURK_FRIEND_COMMENTS_ONLY=2;
    int plurk_id;
    String qualifier;
    int status;
    int plurkType;
    int userID;
    int ownerID;
    Date posted;
    int noComments;
    String content;
    String contentRaw;
    int responseCount;
    int responsesSeen;
    int [] limitedToUsers;
    
    PlurkUser owner;
    
    public Plurk(JSONObject data, boolean isPlurk) {
    	parse(data,isPlurk);
    }
    
    public void parse(JSONObject data, boolean isPlurk) {
        	status=data.optInt("is_unread",0);
        	plurkType=data.optInt("plurk_type",0);
        	ownerID=data.optInt("owner_id",0);
        	noComments=data.optInt("no_comments",0);
        	responseCount=data.optInt("response_count",0);
	        responsesSeen=data.optInt("responses_seen",0);
    		plurk_id=data.optInt("plurk_id",0);
	        qualifier=data.optString("qualifier","");
	        userID=data.optInt("user_id",0);
	        posted=new Date(data.optString("posted",DateTime.now().toString()));
	        content=data.optString("content","");
	        contentRaw=data.optString("content_raw","");
    }

    public static List<Plurk> getPlurks(JSONArray plurks,boolean isPlurk) {
    	List<Plurk> list=null;
    	if(plurks.length()>0) {
    		list=new LinkedList<Plurk>();
		}
    	Plurk p;
		for(int x=0;x<plurks.length();x++) {
			try {
				p=new Plurk(plurks.getJSONObject(x),isPlurk);
				list.add(p);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
    
	public int getPlurk_id() {
		return plurk_id;
	}

	public void setPlurk_id(int plurkId) {
		plurk_id = plurkId;
	}

	public String getQualifier() {
		return qualifier;
	}

	public void setQualifier(String qualifier) {
		this.qualifier = qualifier;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getPlurkType() {
		return plurkType;
	}

	public void setPlurkType(int plurkType) {
		this.plurkType = plurkType;
	}

	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public int getOwnerID() {
		return ownerID;
	}

	public void setOwnerID(int ownerID) {
		this.ownerID = ownerID;
	}

	public Date getPosted() {
		return posted;
	}

	public void setPosted(Date posted) {
		this.posted = posted;
	}

	public int getNoComments() {
		return noComments;
	}

	public void setNoComments(int noComments) {
		this.noComments = noComments;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getContentRaw() {
		return contentRaw;
	}

	public void setContentRaw(String contentRaw) {
		this.contentRaw = contentRaw;
	}

	public int getResponseCount() {
		return responseCount;
	}

	public void setResponseCount(int responseCount) {
		this.responseCount = responseCount;
	}

	public int getResponsesSeen() {
		return responsesSeen;
	}

	public void setResponsesSeen(int responsesSeen) {
		this.responsesSeen = responsesSeen;
	}

	public int[] getLimitedToUsers() {
		return limitedToUsers;
	}

	public void setLimitedToUsers(int[] limitedToUsers) {
		this.limitedToUsers = limitedToUsers;
	}

	public PlurkUser getOwner() {
		return owner;
	}

	public void setOwner(PlurkUser owner) {
		this.owner = owner;
	}


}
